package com.itheima.protocol.MulticastDemo;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.concurrent.TimeUnit;


public class MulticastServer {

    public static void main(String[] args) {

        try {

            InetAddress group = InetAddress.getByName("224.5.6.7");
            MulticastSocket multicastSocket = new MulticastSocket();
            for (int i=0;i<10;i++){
                String data = "Hello xiaowang";
                byte[] bytes = data.getBytes();
                multicastSocket.send(new DatagramPacket(bytes,bytes.length,group,8888));
                TimeUnit.SECONDS.sleep(2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
